<?

class config
{
	protected static $data = array();
	protected static $instance;

	private function __construct() {}

	public static function init()
	{
		self::load(PROJECT_PATH . '/config/app/production.php');
		self::load(PROJECT_PATH . '/config/app/' . application::get_env() . '.php');
		
		if ( is_file($override = PROJECT_PATH . '/config/app/override.php') )
			self::load($override);
	}
	
	public static function load( $file )
	{
		$config = include $file;
		self::$data = array_merge( self::$data, $config );
	}

	public static function get($key, $default = null)
	{
		if ( array_key_exists($key, self::$data) )
		{
			return self::$data[$key];
		}

		return $default;
	}
	
	public static function set( $key, $value )
	{
		self::$data[$key] = $value;
	}

	public static function all()
	{
		return self::$instance ? self::$instance : self::$instance = new self;
	}

	public function __get( $name )
	{
		return self::$data[$name];
	}
}